package com.yitao.cms.service.order;

import com.skipper.base.data.querydsl.PredicateBuilder;
import com.skipper.base.service.GenericEntityService;
import com.yitao.client.dto.order.MallOrderRefundDetailDto;
import com.yitao.client.model.order.MallOrderRefundDetailModel;
import com.yitao.client.model.order.QMallOrderRefundDetailModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.List;

@Service
public class CmsMallOrderRefundDetailService extends GenericEntityService<MallOrderRefundDetailModel, MallOrderRefundDetailDto, QMallOrderRefundDetailModel> {

    public CmsMallOrderRefundDetailService(EntityManager entityManager) {
        super(entityManager);
    }

    public List<MallOrderRefundDetailModel> getMallOrderRefundDetailModelListByRefundId(Long refundId) {
        return queryFactory.select(Q).from(Q).where(Q.refundId.eq(refundId)).fetch();

    }

    @Transactional
    public void saveList(List<MallOrderRefundDetailModel> mallOrderRefundDetailModelList) {
        repository.save(mallOrderRefundDetailModelList);
    }

    /**
     *
     * 功能描述: 根据退款申请id获取缺货商品详情和数量
     *
     * @param refundId 退款申请id
     * @return
     * @auther: Kien
     * @date: 2019/5/15 11:08
     */
    public List<MallOrderRefundDetailModel> findByRefundId(Long refundId){
        List<MallOrderRefundDetailModel> list = repository.findAll(PredicateBuilder.conjunction()
                .and(() -> Q.refundId.eq(refundId))
                .get());
        return list;
    }
}